package logic

import (
	"context"
	"tiktok/models/mysql"

	"tiktok/tiktokrpc/internal/svc"
	"tiktok/tiktokrpc/tiktokrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type NoteListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewNoteListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NoteListLogic {
	return &NoteListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 笔记列表
func (l *NoteListLogic) NoteList(in *tiktokrpc.NoteListRequest) (*tiktokrpc.NoteListResponse, error) {
	// todo: add your logic here and delete this line
	pagesize := (in.Page - 1) * in.Size
	var not []mysql.Note
	mysql.DB.Offset(int(pagesize)).Limit(int(in.Size)).Find(&not)
	var nots []*tiktokrpc.Lists
	for _, i := range not {
		list := tiktokrpc.Lists{
			UserId:  int64(i.UserId),
			Title:   i.Title,
			Context: i.Context,
		}
		nots = append(nots, &list)
	}
	return &tiktokrpc.NoteListResponse{
		List: nots,
	}, nil
}
